package sctu.edu.java.year2016.team08.lisonghong.day20160616.chapter17_1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created by 松红 on 2016/6/16.
 * 删除表中年龄为20 的记录
 */
public class Age {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("找不到驱动类");
        }
        try {
            String url = "jdbc:mysql://localhost:3306/lsongh";
            String user = "root";
            String Password = "";
            Connection conn = DriverManager.getConnection(url, user, Password);
            String sql = "delete from songh where age=20";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.executeUpdate(sql);
            conn.close();
        } catch (SQLException e) {
            System.out.println("找不到数据库");
        }
    }
}
